<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/modules/school/front/include/taglib.jsp" %>
<c:set var="ctxA" value="${pageContext.request.contextPath}${fns:getAdminPath()}"/>
<html>
<head>
    <title>书籍统计</title>
    <meta name="decorator" content="default"/>
    <%@include file="/WEB-INF/views/include/treeview.jsp" %>
    <style type="text/css">
        .ztree {overflow:auto;margin:0;_margin-top:10px;padding:10px 0 0 10px;}
    </style>
</head>
<body>
<div id="content" class="row-fluid">
    <div id="left" class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle">分类<i class="icon-refresh pull-right" onclick="refreshTree();"></i><div class="pull-right" id="collapseBtn">折叠</div></a>
        </div>
        <div id="ztree" class="ztree"></div>
    </div>
    <div id="openClose" class="close">&nbsp;</div>
    <div id="right">
        <iframe id="booksContent" src="${ctx}/svschoolinfo/booksAmount" width="100%" height="91%" frameborder="0"></iframe>
    </div>
</div>
<script type="text/javascript">
    var setting = {data:{simpleData:{enable:true,idKey:"id",pIdKey:"pId",rootPId:'0'}},
        callback:{onClick:function(event, treeId, treeNode){
            var classcode = treeNode.classcode == '0' ? '' :treeNode.classcode;
            $('#booksContent').attr("src","${ctx}/svschoolinfo/booksAmount?classcode="+classcode);
        }
        }
    };

    function refreshTree(){
        $.getJSON("${ctxA}/book/bktype/treeData",function(data){
            $.fn.zTree.init($("#ztree"), setting, data).expandAll(true);
        });
    }
    refreshTree();

    var leftWidth = 240; // 左侧窗口大小
    var htmlObj = $("html"), mainObj = $("#main");
    var frameObj = $("#left, #openClose, #right, #right iframe");
    function wSize(){
        var strs = getWindowSize().toString().split(",");
        htmlObj.css({"overflow-x":"hidden", "overflow-y":"hidden"});
        mainObj.css("width","auto");
        frameObj.height(strs[0] - 5);
        var leftWidth = ($("#left").width() < 0 ? 0 : $("#left").width());
        $("#right").width($("#content").width()- leftWidth - $("#openClose").width() -5);
        $(".ztree").width(leftWidth - 10).height(frameObj.height() - 46);
    }
    function expandNode(e) {
        var zTree = $.fn.zTree.getZTreeObj("ztree"),
                type = e.data.type;

        var nodes = zTree.getNodesByParam("pId", "0", null);

        if (type == "expandAll") {
            zTree.expandAll(true);
        } else if (type == "collapseAll") {
            zTree.expandAll(false);
        } else {
            var callbackFlag = $("#ztree").attr("checked");
            for (var i=0, l=nodes.length; i<l; i++) {
                zTree.setting.view.fontCss = {};
                if (type == "expand") {
                    zTree.expandNode(nodes[i], true, null, null, callbackFlag);
                } else if (type == "collapse") {
                    zTree.expandNode(nodes[i], false, null, null, callbackFlag);
                } else if (type == "toggle") {
                    zTree.expandNode(nodes[i], null, null, null, callbackFlag);
                } else if (type == "expandSon") {
                    zTree.expandNode(nodes[i], true, true, null, callbackFlag);
                } else if (type == "collapseSon") {
                    zTree.expandNode(nodes[i], false, true, null, callbackFlag);
                }
            }
        }
    }
    $(document).ready(function() {
        refreshTree();
        $("#collapseBtn").bind("click", {type: "collapse"}, expandNode);
    });
</script>
<script src="${ctxStatic}/common/wsize.min.js" type="text/javascript"></script>
</body>
</html>